// alpha/pages/alpha_template_detail/add_purchase_order/index.js
const common = require("../../../utils/common.js");
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rowData: {}, // 要操作的数据
    rowIndex: null, // 要操作的数据的行
    isField: '', // 要操作的
    showSupplierSelection: false, // 供应商选择显示
    showPurchasingCompany: false, // 下单人选择显示
    showMaterialInquiry: false, // 物料选择
    showRequisitionForm: false, // 需求单选择
    confOrderTypeList: [], // 类型选择
    isPushGroupList: [
        {
            name:"是",
            value:1
        },
        {
            name:"否",
            value:0
        }
    ],
    buyerList: [], // 采购员
    unitList: [], // 单位下拉数据
    formData: {
      confOrderType: '', // 产品类型
      confOrderTypeName: '', // 产品类型
      isPushGroup: 1, // 产品类型
      isPushGroupName: '是', // 产品类型
      recommendSupplierId: '', // 供应商id
      recommendSupplierName: '', // 供应商名称
      recommendSupplierCode: '', // 供应商Code
      purchaserId: '', // 采购员id
      purchaserName: '', // 采购员
      purchaseSupplierCod: '', // 下单人编码
      purchaseSupplierId: '', // 下单人id
      purchaseSupplierName: '', // 下单名称
      purchaseModel: '', // 季节
      purchaseModelName: '', // 季节名称
      settleType: '', // 结算方式
      settleTypeName: '', // 结算方式名称
      settleRule: '', // 结算规则
      settleRuleName: '', // 结算规则名称
      settleRemark: "" // 其他结算方式备注
    },
    materielList: [],
    purchaseModelList: [],
    settleTypeList: [],
    settleRuleList: [],
    materialInquiryMultiple: false, // 物料多选/单选
    showAppointmet: false, // 时间选择器
    currentDate: new Date().getTime(),
    minDate: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      } else if (type === 'day') {
        return `${value}日`;
      }
      return value;
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getconfOrderTypeList()
    this.get_buyerList()
    this.getPurchaseModelList()
    this.getSettleTypeList()
    this.getUnitList()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  async getconfOrderTypeList() {
    try {
      const res = await common.request_api("/api/erp/baseDictionary/queryCommonDictionaryAndChild/confOrderCategory?code=2007", null, true, 'get')
      if (res.code === 200) {
        this.setData({
          confOrderTypeList: res.data
        })
      }
    } catch {

    }
  },
  handlePickerChange(e) {
    const value = e.detail.value
    const formName = e.target.dataset.formname
    const isValue = e.target.dataset.value
    const isValueName = e.target.dataset.valuename
    const listName = e.target.dataset.listname
    let data = this.data[listName][e.detail.value]
    const formData = this.data[formName]
    formData[isValue] = data.value
    formData[isValueName] = data.name
    console.log(formData);
    this.setData({
      formData
    });
    if (isValue === 'settleType') {
      this.getSettleRuleList(data.value)
    }
  },
  bindKeyInput(e) {
    const isValue = e.target.dataset.value
    const formName = e.target.dataset.formname
    const formData = this.data[formName]
    formData[isValue] = e.detail.value
    this.setData({
      formData
    })
  },
  handleSelectSupplier(e) {
    const name = e.currentTarget.dataset.name
    this.setData({
      [name]: true
    })
  },
  handleSupplierSelect(event, flag = false) {
    const detail = event.detail
    console.log(detail,'detail');
    let materielList = this.data.materielList
    console.log(materielList);
    if (materielList && materielList.length > 0 && !flag) {
      const _that = this
      wx.showModal({
        title: '提示',
        content: '切换供应商会清除不是该供应商的物料数据！',
        success (res) {
          if (res.confirm) {
            materielList = materielList.filter(p => p.supplierId === detail.supplierId)
            _that.setData({
              materielList
            })
            _that.newHandleSupplierSelect(event)
          } else if (res.cancel) {
          }
        }
      })
    } else {
      this.newHandleSupplierSelect(event)
    }
  },
  handlePurchasingCompany(event, flag = false) {
    const detail = event.detail
    const formData =  this.data.formData
    formData.purchaseSupplierCod = detail.enterpriseCode || ""
    formData.purchaseSupplierName = detail.enterpriseName || ""
    formData.purchaseSupplierId = detail.id || ""
    this.setData({
      formData
    })
  },
  newHandleSupplierSelect(event) {
    const detail = event.detail
    this.setData({
      'formData.contractNo': "",
      'formData.contractId': "",
      'formData.agreementInfoRemark': "",
      'formData.deliveryWarehouseCode': '',
      'formData.deliveryWarehouseName': '',
      'formData.receiveWarehouseCode': '',
      'formData.deliveryWarehouseName': ''
    })
    this.setData({
      'formData.recommendSupplierId': detail.supplierId,
      'formData.recommendSupplierName': detail.supplierShortName,
      'formData.recommendSupplierCode': detail.supplierCode,
    })
    if (detail.supplierId) {
      this.getDefaultAgreementBySupplierId(detail.supplierId)
      this.getOneWarehouse(true)
    }
  },
  async getDefaultAgreementBySupplierId(id) {
    const result = await common.request_api(`/api/erp/mdSupplierAgreementInfo/getDefaultAgreementBySupplierId/${id}`, null, true, 'get')
    if (result.code === 200) {
      this.setData({
        'formData.contractNo': result.data && result.data.contractNo ? result.data.contractNo : "",
        'formData.contractId': result.data && result.data.id ? result.data.id : "",
        'formData.agreementInfoRemark': result.data && result.data.remark ? result.data.remark : ""
      })
    }
  },
  async getOneWarehouse(isSet) {
    const result = await common.request_api(`/api/erp/BaseWarehouse/getOneWarehouse`, {
      supplierCode: this.data.formData.recommendSupplierCode,
      warehouseType: "390201"
    }, true, 'post')

    if (result.code === 200 && result.data.warehouseCode) {
      // this.receiveWareList = [result.data]
      if (isSet) {
        this.setData({
          'formData.deliveryWarehouseCode': result.data.warehouseCode,
          'formData.deliveryWarehouseName': result.data.warehouseName
        })
      }
    }
    const result1 = await common.request_api(`/api/erp/BaseWarehouse/getOneWarehouse`, {
      supplierCode: this.data.formData.recommendSupplierCode,
      warehouseType: "390207"
    }, true, 'post')
    if (result1.code === 200 && result1.data.warehouseCode) {
      // this.receiveWareList = [result1.data]
      if (isSet) {
        this.setData({
          'formData.receiveWarehouseCode': result1.data.warehouseCode,
          'formData.deliveryWarehouseName': result1.data.warehouseName
        })
      }
    }
  },
  // 获取采购员
  async get_buyerList () {
    // 发起请求
    const userInfo = await common.request_api('/api/ums/user/user/info', {}, false, 'get');
    const result = common.request_api('/api/ums/positionDuty/queryDropUserByDutyCode/materialPurchaser', {}, false, 'get');
    result.then(res => {
      const findObj = res.data.find(p => p.value === userInfo.data.id)
      if (findObj) {
        this.setData({
          "formData.purchaserId": findObj.value,
          "formData.purchaserName": findObj.name,
        });
      }
      this.setData({
        buyerList: res.data
      });
    });
  },
  // 获取季节
  getPurchaseModelList: function () {
    // 发起请求
    const result = common.request_api('/api/erp/baseDictionary/queryByGroupIdentification/purchaseModel', {}, false, 'get');
    result.then(res => {
      this.setData({
        purchaseModelList: res.data
      });
    });
  },
  // 结算方式
  getSettleTypeList: function () {
    // 发起请求
    const result = common.request_api('/api//erp/baseDictionary/queryByGroupIdentification/settleType', {}, false, 'get');
    result.then(res => {
      this.setData({
        settleTypeList: res.data
      });
    });
  },
  // 结算规则
  getSettleRuleList: function (val) {
    // 发起请求
    const result = common.request_api(`/api/erp/baseDictionary/queryCommonDictionaryAndChild/settleType?code=${val}`, {}, false, 'get');
    result.then(res => {
      this.setData({
        settleRuleList: res.data,
        'formData.settleRule': '',
        'formData.settleRuleName': '',
      });
    });
  },
  // 获取单位
  getUnitList: function () {
    // 发起请求
    const result = common.request_api('/api/pdm/commonDictionary/queryByGroupIdentification/unit', {}, false, 'get');
    result.then(res => {
      this.setData({
        unitList: res.data
      });
    });
  },

  handleClose(e) {
    const name = e.target.dataset.name
    this.setData({
      [name]: false
    })
  },
  handleShow(e) {
    const field = e.currentTarget.dataset.field
    const item = e.currentTarget.dataset.item
    const index = e.currentTarget.dataset.index
    const name = e.currentTarget.dataset.name
    this.setData({
      [name]: true,
      rowData: item,
      rowIndex: index,
      isField: field,
    })
  },
  // 输入框改变
  inputChange(e) {
    const field = e.currentTarget.dataset.field
    const index = e.currentTarget.dataset.index
    let {
      value
    } = e.detail
    this.data.materielList[index][field] = value
    if (field === 'demandQty') {
      this.data.materielList[index]['orderQty'] = value
      this.data.materielList[index]['totalQty'] = value
      this.data.materielList[index]['purchaseQty'] = value
      this.data.materielList[index]['calQty'] = value
      this.getAmount(index)
    } else if (field === 'confirmPrice') {
      this.data.materielList[index]['setConfirmPrice'] = this.toFixedNoTrailingZeros(Number(value) * Number(1))
      this.getAmount(index)
    }
  },
  getAmount(index) { // 采购金额
    let orderUnitAmount = ''
    const confirmPrice = this.data.materielList[index].confirmPrice
    const purchaseQty = this.data.materielList[index].purchaseQty
    orderUnitAmount = Number(confirmPrice || 0) * Number(purchaseQty || 0)
    this.data.materielList[index].orderUnitAmount = orderUnitAmount
  },
  toFixedNoTrailingZeros(number) {
    if (number) {
      number = parseFloat(parseFloat(number).toFixed(4))
      // 转换为字符串以便进行操作
      let numberString = number.toString();
      // 使用正则表达式去掉小数末尾的零
      numberString = numberString.replace(/(?:\.0*|(\.\d+?)0+)$/, "$1");
      // 转换回数字类型
      return parseFloat(numberString);
    } else {
      return number
    }
  },
  async timeConfirm(e) {
    const value = this.filterTime(e.detail, '{y}-{m}-{d}')
    const materielList = this.data.materielList
    materielList[this.data.rowIndex][this.data.isField] = value
    this.setData({
      showAppointmet: false,
      materielList

    })
  },
  filterTime(time, cFormat) {
    const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}"
    const date = new Date(time)
    const Y = date.getFullYear()
    const M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
    const D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    const H = date.getHours() < 10 ? '0' + date.getHours() : date.getHours() // 小时
    const I = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() // 分钟
    const S = date.getSeconds() // 秒
    const formatObj = {
      y: Y,
      m: M,
      d: D,
      h: H,
      i: I,
      s: S
    }
    const time_str = format.replace(/{(y|m|d|h|i|s)+}/g, (result, key) => {
      let value = formatObj[key]
      return value || 0
    })
    return time_str
  },
  // 批量显示绑定物料
  handlemMateriel() {
    this.setData({
      showMaterialInquiry: true,
      materialInquiryMultiple: true
    })
  },
  // 单选显示绑定物料
  handlemMaterielRow(e) {
    const index = e.currentTarget.dataset.index
    const item = e.currentTarget.dataset.item
    this.setData({
      showMaterialInquiry: true,
      materialInquiryMultiple: false,
      rowIndex: index,
      rowData: item
    })
  },
  // 选择需求单
  handlemRequisitionFormRow(e) {
    const index = e.currentTarget.dataset.index
    const item = e.currentTarget.dataset.item
    this.setData({
      showRequisitionForm: true,
      rowIndex: index,
      rowData: item
    })
  },
  genId() {
    return Number(Math.random().toString().substr(3, 10) + Date.now()).toString(36)
  },
  // 物料选择
  handleSelect(event) {
    const materielList = this.data.materielList
    if (this.data.materialInquiryMultiple) {
      const list = event.detail
      list.forEach((dto, dtoIndex) => {
        const index = materielList.findIndex((i) => (i.sku === "" || !i.sku) && !i.delete)
        if (index !== -1) {
          dto.constId = materielList[index].constId
          dto.id = ""
          materielList[index] = dto
          this.getMaterials(materielList[index], dto)
        } else if(!materielList.find(p => p.sku === dto.materialSku)){
          dto.constId = this.genId()
          dto.delete = false
          dto.isDisplayed = true
          dto.id = ""
          dto.spareDemandPlanCode = ""
          dto.spareClothSalesOrderCode = ""
          dto.spareClothPurOrderCode = ""
          dto.spareCustomerSpu = ""
          dto.spareSpu = ""
          dto.additionalCharge = 0
          dto.taxRate = "0"
          dto.stockBelongHome = '',
            dto.stockBelongHomeName = '',
            dto.stockBelongType = '',
            dto.stockBelongTypeName = ''
          const num = materielList.length
          materielList.push(JSON.parse(JSON.stringify(dto)))
          this.getMaterials(materielList[num], dto)
        }
      })
      this.setData({
        materielList: materielList
      })
    } else if (!materielList.find(p => p.sku === row.materialSku)){
      const row = event.detail.row
      let materielList = this.data.materielList
      materielList.forEach((item, index) => {
        if (index === this.data.rowIndex) {
          console.log(row, 'row');
          this.getMaterials(item, row)
          console.log(item, 'item');
        }
      })
      this.setData({
        materielList
      })
    }
  },
  // 需求单选择
  handleRequisitionForm(event) {
    const callBackData = event.detail.row
    let materielList = this.data.materielList
    materielList.forEach((item, index) => {
      if (index === this.data.rowIndex) {
        item.clothingQty = callBackData.orderQty
        item.spareDesigner = callBackData.designUserName || ''
        item.spareColor = callBackData.skcName
        item.clothingSku = callBackData.sku
        // row.spareClothSalesOrderCode = callBackData.orderCode
        item.spareClothPurOrderCode = callBackData.orderCode
        item.spareSpu = callBackData.spu
        item.spareSpuName = callBackData.spuName
        item.spareCustomer = callBackData.customerCode
        item.spareCustomerSpu = callBackData.customerSpu ? callBackData.customerSpu : ""
        item.productClassificationText = callBackData.productClassificationText ?
          callBackData.productClassificationText :
          ""
      }
    })
    this.setData({
      materielList
    })
  },
  async getMaterials(row, callBackData) {
    row.supplierId = ""
    for (let i = 0; i < this.data.materielList.length; i++) {
      if (
        this.data.materielList[i].supplierId &&
        callBackData.supplierId &&
        this.data.materielList[i].supplierId !== callBackData.supplierId
      ) {
        row.skuId = null
        wx.showToast({
          title: '请选择相同供应商数据！',
          icon: 'error',
          duration: 2000,
        });
        return
      }
    }
    console.log(32434);
    row.supplierId = ""
    row.spuName = callBackData.materialName
    row.skuCode = callBackData.skuCode
    row.skc = callBackData.materialColor
    row.skcName = callBackData.materialColor
    // 获取单据单位
    // 根据单据单位配置，获取单据单位
    const filterObj = callBackData.categoryUnitList && callBackData.categoryUnitList.find(uu => uu.systemAndCategory === 'ERP-2007')
    if (filterObj) {
      const isUnitBoj = this.data.unitList.find(unit => unit.value === filterObj.orderUnit)
      row.purchaseUnit = isUnitBoj ? isUnitBoj.value : filterObj.orderUnit || ''
      row.purchaseUnitName = isUnitBoj ? isUnitBoj.label : filterObj.orderUnitName || ''
    }
    // 获取换算系数
    let confirmationMax = ''
    let confirmation = ''
    if (row.sourceUnit && row.purchaseUnit && callBackData.confirmationCoefficientDtoList && callBackData.confirmationCoefficientDtoList.length > 0) {
      callBackData.confirmationCoefficientDtoList && callBackData.confirmationCoefficientDtoList.forEach(arr => {
        // 原始单位baseUnit  来源单位
        // 目标单位purchaseUnit  单据单位
        if (row.sourceUnit === arr.purchasingUnit && row.purchaseUnit === arr.baseUnit) { // 采购单位 = 目标单位
          // confirmation = arr.confirmationCoefficient || 1
          confirmation = this.toFixedNoTrailingZeros(1 / (arr.confirmationCoefficient || 0))
        }
        if (row.sourceUnit === arr.baseUnit && row.purchaseUnit === arr.purchasingUnit) {
          confirmationMax = arr.confirmationCoefficient || 1
        }
      })
      if (row.sourceUnit === row.purchaseUnit) {
        confirmation = 1
      }
    }
    row.conversionFactor = confirmationMax ? confirmationMax : confirmation
    row.sku = callBackData.materialSku
    row.materialSku = callBackData.supplierSkuCode ? callBackData.supplierSkuCode : ""
    row.skuName = callBackData.materialColor + "," + (callBackData.spec || '')
    row.materialSkuName = callBackData.supplierColor + "," + (callBackData.supplierSpec || '')
    row.spu = callBackData.materialCode
    row.baseUnit = callBackData.basicUnit
    row.baseUnitName = callBackData.basicUnitName
    row.thumbnailsUrl = callBackData.image
    row.supplierSpu = callBackData.supplierSpu
    row.supplierColor = callBackData.supplierColor
    row.supplierId = callBackData.supplierId
    row.orderQty = row.orderQty ? row.orderQty : ""
    row.totalQty = row.totalQty ? row.totalQty : ""
    row.demandQty = row.orderQty ? this.toFixedNoTrailingZeros(row.orderQty * Number(row.conversionFactor || 1)) : ""
    row.purchaseQty = row.purchaseQty ? row.purchaseQty : ""
    row.purchaseQty = row.purchaseQty ? this.toFixedNoTrailingZeros(Number(row.purchaseQty) * Number(row.conversionFactor)) : ""
    row.totalKilograms = row.totalKilograms ? row.totalKilograms : 1
    row.startingQuantity = callBackData.startingQuantity || 0
    row.reservedStockQty = callBackData.reservedStockQty ? callBackData.reservedStockQty : 0
    row.reservedTransitQty = callBackData.reservedTransitQty ? callBackData.reservedTransitQty : 0
    row.totalKilograms = callBackData.totalKilograms ? callBackData.totalKilograms : 1
    row.calQty = row.demandQty ? this.toFixedNoTrailingZeros(row.demandQty / row.totalKilograms) : ""
    const confirmPrice = callBackData.plateCuttingPrice ? callBackData.plateCuttingPrice : row.confirmPrice
    row.placeholderConfirmPrice = confirmPrice
    row.confirmPrice = ''
    row.setConfirmPrice = row.confirmPrice && row.conversionFactor ? this.toFixedNoTrailingZeros(Number(row.confirmPrice) * Number(row.conversionFactor || 1)) : 0
    row.plateCuttingPrice = callBackData.plateCuttingPrice ? callBackData.plateCuttingPrice : ""
    row.bigGoodsPrice = callBackData.bigGoodsPrice ? callBackData.bigGoodsPrice : ""
    row.supplierShortName = callBackData.supplierName ? callBackData.supplierName : ""
    // 赋值主表的供应商信息
    if (callBackData.supplierId) {
      const supplierData = JSON.parse(JSON.stringify(callBackData))
      supplierData.id = callBackData.supplierId
      supplierData.supplierShortName = callBackData.supplierName
      this.handleSupplierSelect({
        detail: supplierData
      }, true)
    }
  },
  toFixedNoTrailingZeros(number) {
    if (number) {
      number = parseFloat(parseFloat(number).toFixed(4))
      // 转换为字符串以便进行操作
      let numberString = number.toString();
      // 使用正则表达式去掉小数末尾的零
      numberString = numberString.replace(/(?:\.0*|(\.\d+?)0+)$/, "$1");
      // 转换回数字类型
      return parseFloat(numberString);
    } else {
      return number
    }
  },
  // 删除物料
  handleDelete(e) {
    const index = e.currentTarget.dataset.index
    const item = e.currentTarget.dataset.item
    const materielList = this.data.materielList
    materielList.splice(index, 1)
    this.setData({
      materielList
    })
  },
  // 取消回退
  handleCancel() {
    wx.navigateBack({
      delta: 1
    })
  },
  // 保存物料
  async handleSubmitForm() {
    const formData = this.data.formData
    console.log(formData);
    const materielList = this.data.materielList
    if (!formData.confOrderType) {
      wx.showToast({
        title: '请选择单据类型！',
        icon: 'error',
      })
      return
    } else if (!formData.recommendSupplierId) {
      wx.showToast({
        title: '请选择供应商！',
        icon: 'error',
      })
      return
    } else if (!formData.purchaserId) {
      wx.showToast({
        title: '请选择采购员！',
        icon: 'error',
      })
      return
    } else if (!formData.purchaseSupplierId) {
      wx.showToast({
        title: '请选择下单人！',
        icon: 'error',
      })
      return
    } else if (!formData.purchaseModel) {
      wx.showToast({
        title: '请选择季节！',
        icon: 'error',
      })
      return
    } else if (!formData.settleType) {
      wx.showToast({
        title: '请选择结算方式！',
        icon: 'error',
      })
      return
    }  else if (!formData.settleRule) {
      wx.showToast({
        title: '请选择结算规则！',
        icon: 'error',
      })
      return
    } 
    if (!materielList || materielList && materielList.length === 0) {
      wx.showToast({
        title: '请添加物料信息！',
        icon: 'error',
      })
      return
    }
    for(let i=0; i< materielList.length; i++) {
      let item = materielList[i]
      if(!item.spuName) {
        wx.showToast({
          title: `第${i + 1}条请选择物料信息！`,
          icon: 'none',
        })
        return
      }else if(!item.confirmPrice) {
        wx.showToast({
          title: `第${i + 1}请输入采购价！`,
          icon: 'none',
        })
        return
      }else if(!item.demandQty) {
        wx.showToast({
          title: `第${i + 1}请输入采购数量！`,
          icon: 'none',
        })
        return
      }else if(formData.confOrderType === '200701-00' && !item.spareClothPurOrderCode) {
        wx.showToast({
          title: `第${i + 1}请选择需求计划！`,
          icon: 'none',
        })
        return
      }
    }
    
    materielList.forEach(item => {
      if (!item.stockBelongType && !item.stockBelongHome) {
        item.stockBelongType = '1'
        item.stockBelongTypeName = '公共'
        item.stockBelongHome = '公共'
        item.stockBelongHomeName = '公共'
      }
      item.sourceDetailDtos &&
        item.sourceDetailDtos.forEach((list) => {
          list.additionalQty = null
          list.orderQty = list.demandQty
          list.orderQty = item.orderQty
          list.totalQty = item.totalQty
          list.demandQty = item.demandQty
          list.additionalQty = item.additionalQty
        })
        if (item.expandTable) {
          delete item.expandTable
        }
        if (item.askReturnDate && item.askReturnDate.length === 10) {
          item.askReturnDate = item.askReturnDate + " " + "23:59:59"
        }
        if (item.lineData) {
          delete item.lineData
        }
    })
    const createDate = {
      ...formData,
      detailDtos: materielList,
      receiverArea: formData.receiverArea ? formData.receiverArea.toString() : "",
      submit: true,
      purchaseOrderType: 2007,
      confOrderCategory: 2007,
      relateType: '3',
      year: (new Date().getFullYear()).toString()
    }
    const  res = await common.request_api('/api/erp/purOrder/createPurOrder?orderType=MRP_PUR', createDate, true, 'post');
    if (res.code === 200) {
      wx.navigateBack({
        delta: 1,
        success:()=>{
          wx.showToast({
            title: '新增采购单成功！',
            icon: 'success',
          })
        }
      })
    }
  }
})